﻿using System;
using System.IO;
using System.Net.Sockets;

namespace WebTranslator {
	public abstract class Protocol {
		public StreamReader streamReader { get; set; }
		public StreamWriter streamWriter { get; set; }
		public NetworkStream networkStream { get; set; }
		public virtual void Send(String message) {
			try {
				Console.WriteLine("Wysylam: " + message);
				streamWriter.WriteLine(message);
				streamWriter.Flush();
				return;
			} catch (Exception e) {
				Console.Write(e.Message);
				return;
			}
		}
		public void SetSockets(Socket socket) {
			networkStream = new NetworkStream(socket);
			streamWriter = new StreamWriter(networkStream);
			streamReader = new StreamReader(networkStream);
		}
		public virtual string Receive() {
			string s = streamReader.ReadLine();
			Console.WriteLine("Odebralem: " + s);
			return s;
		}

		public virtual void Disconnect() {
			//Send("quit");
			this.streamReader.Close();
			this.streamWriter.Close();
			this.networkStream.Close();
		}
	}
}
